package com.mayuhao.userstudent.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mayuhao.userstudent.entity.UserStudent;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 马宇豪
 * @since 2022-10-27
 */
public interface UserStudentMapper extends BaseMapper<UserStudent> {

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.mayuhao.userstudent.entity.UserStudent>
     * @description 请修改方法描述
     * @methodName page
     * @params [userStudentPage, searchId, searchName]
     * @paramType [com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.mayuhao.userstudent.entity.UserStudent>, java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/27 0027 下午 4:16
     * @email 1757442521@qq.com
     **/
    Page<UserStudent> page(Page<UserStudent> userStudentPage, @Param("searchId") String searchId, @Param("searchName") String searchName);

    /**
     * @return boolean
     * @description 请修改方法描述
     * @methodName chooseCourse
     * @params []
     * @paramType []
     * @author 马宇豪
     * @date 2022/10/27 0027 下午 4:16
     * @email 1757442521@qq.com
     **/
    @Update("UPDATE css_course SET css_course.course_choose_number = css_course.course_choose_number + 1 WHERE  css_course.course_id = #{courseId}")
    boolean chooseCourse(@Param("courseId") String courseId);

    /**
     * @return boolean
     * @description 请修改方法描述
     * @methodName returnCourse
     * @params [courseId]
     * @paramType [java.lang.Integer]
     * @author 马宇豪
     * @date 2022/10/27 0027 下午 4:59
     * @email 1757442521@qq.com
     **/
    @Update("UPDATE css_course SET css_course.course_choose_number = css_course.course_choose_number - 1 WHERE  css_course.course_id = #{courseId}")
    boolean returnCourse(@Param("courseId") String courseId);

    /**
     * @return boolean
     * @description 请修改方法描述
     * @methodName saveChooseCourse
     * @params [studentId, courseId]
     * @paramType [java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/30 0030 下午 8:40
     * @email 1757442521@qq.com
     **/
    @Insert("INSERT INTO css_choose_course VALUES (#{studentId},#{courseId},null)")
    boolean saveChooseCourse(@Param("studentId") String studentId, @Param("courseId") String courseId);

    /**
     * @return boolean
     * @description 请修改方法描述
     * @methodName deleteChooseCourse
     * @params [studentId, courseId]
     * @paramType [java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/30 0030 下午 8:40
     * @email 1757442521@qq.com
     **/
    @Delete("DELETE FROM css_choose_course WHERE css_choose_course.student_id=#{studentId} AND css_choose_course.course_id=#{courseId}")
    boolean deleteChooseCourse(@Param("studentId") String studentId, @Param("courseId") String courseId);


    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.mayuhao.userstudent.entity.UserStudent>
     * @description 请修改方法描述
     * @methodName hasChoosePage
     * @params [userStudentPage, studentId, searchId, searchName]
     * @paramType [com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.mayuhao.userstudent.entity.UserStudent>, java.lang.String, java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/31 0031 上午 10:02
     * @email 1757442521@qq.com
     **/
    Page<UserStudent> hasChoosePage(Page<UserStudent> userStudentPage, @Param("studentId") String studentId, @Param("searchId") String searchId, @Param("searchName") String searchName);

    /**
     * @return java.util.List<com.mayuhao.userstudent.entity.UserStudent>
     * @description 请修改方法描述
     * @methodName selectBeforeChoose
     * @params [courseId]
     * @paramType [java.lang.String]
     * @author 马宇豪
     * @date 2022/11/10 0010 上午 12:23
     * @email 1757442521@qq.com
     **/
//    @Select("SELECT css_choose_course.course_id FROM css_choose_course WHERE css_choose_course.student_id=#{studentId} AND css_choose_course.course_id=#{courseId}")
    @Select("SELECT css_course.course_name FROM css_choose_course INNER JOIN css_course ON css_choose_course.course_id=css_course.course_id WHERE css_choose_course.student_id=#{studentId} ")
    List<UserStudent> selectBeforeChoose(@Param("studentId") String studentId, @Param("courseId") String courseId);

/**
 * @return boolean
 * @description 请修改方法描述
 * @methodName isFullChoose
 * @params [courseId]
 * @paramType [java.lang.String]
 * @author 马宇豪
 * @date 2022/11/13 0013 下午 2:26
 * @email 1757442521@qq.com
 **/
UserStudent isFullChoose(String courseId);

    /**
     * @return java.util.List<com.mayuhao.userstudent.entity.UserStudent>
     * @description 请修改方法描述
     * @methodName howManyChoose
     * @params [studentId]
     * @paramType [java.lang.String]
     * @author 马宇豪
     * @date 2022/11/13 0013 下午 3:10
     * @email 1757442521@qq.com
     **/
    @Select("SELECT css_choose_course.course_id FROM css_choose_course WHERE css_choose_course.student_id=#{studentId}")
    List<UserStudent> howManyChoose(String studentId);

    /**
     * @return java.util.List<com.mayuhao.userstudent.entity.UserStudent>
     * @description 请修改方法描述
     * @methodName scheduleSelect
     * @params []
     * @paramType []
     * @author 马宇豪
     * @date 2022/11/13 0013 下午 4:51
     * @email 1757442521@qq.com
     **/
    List<UserStudent> scheduleSelect();

    List<UserStudent> selectBeforeChooseFindGoCourseTime(String studentId);
}
